package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bfc.service.UnitService;
import org.dom4j.Element;

/**
 * @author hlp
 * @date 2023/2/8 15:16
 * @Description:
 */
public class UnitApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("findUnit")) { //获取可用的预算单位信息给代理银行的业务场景
            String cantonid = body.selectSingleNode("//root/body/cantonid").getText();
            UnitService unitService = (UnitService) SpringContextUtil.getBean("unitService");
            return unitService.findUnit(Long.valueOf(cantonid));

        } else if (head.equals("selUnit")) { //  向财政主动获取预算单位
            String cantonid = body.selectSingleNode("//root/body/cantonid").getText();
            String unitcode = body.selectSingleNode("//root/body/unitcode").getText();

            UnitService unitService = (UnitService) SpringContextUtil.getBean("unitService");
            return unitService.selBaseUnit(cantonid,unitcode);

        }else if (head.equals("findUnitByUnitCode")) {  //获取可用的预算单位信息给代理银行的业务场景
            String cantonid = body.selectSingleNode("//root/body/cantonid").getText();
            String unitcode = body.selectSingleNode("//root/body/unitcode").getText();

            UnitService unitService = (UnitService) SpringContextUtil.getBean("unitService");
            return unitService.findUnitByUnitCode(cantonid,unitcode);

        }else if(head.equals("findUnitByCode")){ //根据 行政区划id 和单位编码查询单位信息
            String cantonid = body.selectSingleNode("//root/body/cantonid").getText();
            String unitcode = body.selectSingleNode("//root/body/unitcode").getText();

            UnitService unitService = (UnitService) SpringContextUtil.getBean("unitService");
            return unitService.findUnitByUnitCode(cantonid,unitcode);

        }

        return null;
    }
}
